home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 366 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: solon.com!not-for-mail
  2. From: stanr@tiac.net (Stan Ryckman)
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion.
  5. Date: 24 Feb 1996 09:35:57 -0600
  6. Organization: Amber & Sneakers Fan Club
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4gnb8t$bgl@solutions.solon.com>
  10. References: <4ggbcq$81c@solutions.solon.com> <4ggg41$91j@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4ggg41$91j@solutions.solon.com>,
  14. Peter Seebach <seebs@solon.com> wrote:
  15. :In article <4ggbcq$81c@solutions.solon.com>,
  16. :Jens M Andreasen  <jens-and@dsv.su.se> wrote:
  17. :>I admit that I am confused too. So in this case the compiler should issue a 
  18. :>warning for { short x = 0; x++; } since "x++" equals "x = x + 1" and both 
  19. :>"x" and "1" are promoted to integers, and there could therefore be a 
  20. :>potential loss of precision because "sizeof(int) > sizeof(short)", but no 
  21. :>precision could have been lost if int and short had been the same (small) 
  22. :>size ?? <phew>
  23. :
  24. :x++ is not the same as "x = x + 1".  "++x" nearly is.
  25.  
  26. However, they *are* all the same in this context (where the value of
  27. the expression is not used, and overflow is impossible).
  28.  
  29. I think you were confused by the line:
  30. :>warning for { short x = 0; x++; } since "x++" equals "x = x + 1" and both 
  31.  
  32. Note that this was an English "for", not a C "for" since otherwise
  33. there would be () rather than {} around the snippet, which is
  34. the equivalent of {short x=1;}.
  35.  
  36. I don't think compilers need to issue warnings for potential loss
  37. of precision in any case, though, but I've been wrong before.
  38. And we all know by now that they *may* issue such warnings at any
  39. time without violating the Standard (even for "x *= 2;").
  40.  
  41. Cheers,
  42. Stan.
  43. --
  44. Stan Ryckman  (stanr@tiac.net) (new e-mail address)
  45.